package com.lanou.controller;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 姚云鹏
 * Create at: 2018/6/11 10:46
 */
@Controller
public class UploadController {
    @RequestMapping("/upload")
    public void upload(@RequestParam("img") CommonsMultipartFile file,
                       HttpServletResponse response)
            throws IOException {
        System.out.println(file.getSize());

        Client client = Client.create();
        String imgPath = "http://127.0.0.1:8088/img/2.jpg";
        WebResource resource = client.resource(imgPath);
        resource.put(file.getInputStream());

        response.getWriter().print(imgPath);
    }
}
